/*
 * @Author: 红尘痴子
 * @Date: 2020-08-31 10:48:12
 * @LastEditTime: 2020-08-31 10:51:35
 * @LastEditors: 红尘痴子
 * @Description:
 * @FilePath: \miaomeimei\utils\qm.js
 * @https://www.jiangcan95.com/
 */
const cmd5 = require('../utils/md5'); //md5加密
const qm = (params) => {
	let key = 'kajsbkd123b55kwbdkj128y87';
	// 参数添加一个当前时间戳
	params.timestamp = Date.parse(new Date()) / 1000;
	let arr1 = params;
	let a = '';
	// 编码排序
	var arr = new Array();
	var num = 0;
	for (var i in arr1) {
		arr[num] = i;
		num++;
	}
	var sortArr = arr.sort();
	var sortObj = {};
	for (var i in sortArr) {
		sortObj[sortArr[i]] = arr1[sortArr[i]];
	}
	// console.log(sortObj, 'sortObj');
	// 拼接字符串
	for (var index in sortObj) {
		if (index != 'sign') {
			a += index + sortObj[index];
		}
		// console.log('key=', index, 'value=', sortObj[index]);
	}
	// console.log(a, '==================================');
	// console.log(api_url + params.url, '==================================');
	// 当前代码添加一个拼接后的参数
	params.sign = cmd5.md5(key + a + key);
	return params;
};
module.exports = {
	qm,
};
